package com.baidu.roomdemo.db

import android.content.Context
import androidx.lifecycle.LiveData

/**
 * 数据访问仓库
 * 中介
 * MVVM设计模式
 */
class Repository(context: Context) {
    private val userDao: UserDao = UserDatabase.getDatabase(context).userDao()

    suspend fun saveUser(user: User){
        userDao.insertUser(user)
    }

    suspend fun deleteUser(user: User){
        userDao.deleteUser(user)
    }

    suspend fun deleteAll(){
        userDao.deleteAll()
    }

    suspend fun updateUser(user: User){
        userDao.updateUser(user)
    }

    fun loadUsers(): LiveData<List<User>>{
        return userDao.loadUsers()
    }
}










